﻿using Azure.Identity;
using FinancialManagement.Application.Command.ReceivableCommand;
using FinancialManagement.Domain.Model;
using FinancialManagement.Infrstructre.Interface;
using MediatR;
using SqlSugar;

namespace FinancialManagement.Application.CommandHandler.ReceivableCommandHandler
{
    /// <summary>
    /// 直接退款的反填
    /// </summary>
    public class FanReceivableNumberCommandHandler : IRequestHandler<FanReceivableNumberCommand, SaleContract>
    {
        ISaleContractRepository scRep;

        public FanReceivableNumberCommandHandler(ISaleContractRepository scRep)
        {
            this.scRep = scRep;
        }

        public async Task<SaleContract> Handle(FanReceivableNumberCommand request, CancellationToken cancellationToken)
        {
            var list = (from sc in await scRep.GetAllAsyns()
                       where sc.SCcontractNumber == request.SCcontractNumber
                       select new SaleContract
                       {
                           ClientName = sc.ClientName
                       }).ToList();
            return list.FirstOrDefault();

        }

    }
}
